package com.crwal.app.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.crwal.app.bean.CrwalUrl;
import com.crwal.app.config.MyCrwalAsync;
import com.crwal.app.service.WebCrwalService;
import com.crwal.app.utils.Constant;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
public class FirstCrwalController {
	
	@Autowired
	private WebCrwalService service;
	@Autowired
	private MyCrwalAsync crwalAsync;

	@GetMapping("/exportAll")
	public String exportAll(String args) throws Exception {
		log.debug("开始全量导出文件。。。");
		List<Map<String, String>> list = CrwalUrl.getList();
		for(Map<String, String> map : list){
			String fileName = map.get("fileName");
			String companyName = map.get("company");
			String companyHref = map.get("companyHref");
			String maxDate = "";
			if(Constant.CrwalFileName.CAGILLNATUREWORKS.getName().equals(fileName)) {
				crwalAsync.natureworksllc(companyName, companyHref, fileName, maxDate);
			} else if(Constant.CrwalFileName.CORBION.getName().equals(fileName)) {
				crwalAsync.corbion(companyName, companyHref, fileName, maxDate);
			} else if(Constant.CrwalFileName.TOTALCORBION.getName().equals(fileName)) {
				crwalAsync.totalcorbion(companyName, companyHref, fileName, maxDate);
			} else if(Constant.CrwalFileName.PTTMCC.getName().equals(fileName)) {
				crwalAsync.pttmcc(companyName, companyHref, fileName, maxDate);
			} else if(Constant.CrwalFileName.CJBIO.getName().equals(fileName)) {
				crwalAsync.cjbio(companyName, companyHref, fileName, maxDate);
			} else if(Constant.CrwalFileName.BASF.getName().equals(fileName)) {
				crwalAsync.basf(companyName, companyHref, fileName, maxDate);
			} else if(Constant.CrwalFileName.ARKEMA.getName().equals(fileName)) {
				crwalAsync.arkema(companyName, companyHref, fileName, maxDate);
			} else if(Constant.CrwalFileName.PLASTICKER.getName().equals(fileName)) {
				crwalAsync.plasticker(companyName, companyHref, fileName, maxDate);
			} else if(Constant.CrwalFileName.BIOPLASTICSNEWS.getName().equals(fileName)) {
				crwalAsync.bioplasticsnews(companyName, companyHref, fileName, maxDate);
			} else if(Constant.CrwalFileName.BIOPLASTICSMAGAZINE.getName().equals(fileName)) {
				crwalAsync.bioplasticsmagazine(companyName, companyHref, fileName, maxDate);
			} else if(Constant.CrwalFileName.PLASTICSNEWS.getName().equals(fileName)) {
				crwalAsync.plasticsnews(companyName, companyHref, fileName, maxDate);
			} else if(Constant.CrwalFileName.BIOBASED.getName().equals(fileName)) {
				crwalAsync.biobased(companyName, companyHref, fileName, maxDate);
			}
		}
		log.debug("全量导出文件完成。。。");
		return "success";
	}
	
	@GetMapping("/test")
	public String readAll() throws Exception {
		service.cjbio("","","");
		//service.plasticsnews("","","2021-04-11");
		return "success";
	}
	

}
